#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import sys
sys.path.append("/home/u18/work/handsetbot/handsetbot")
dsdfds
import time
from engine.common import *
if sys.platform == "darwin":
    adbpath = "adb "
else:
    adbpath = "/usr/bin/adb "
if (sys.argv.__len__())<4:
    print( "参数个数少了")
    exit(0)
handset = sys.argv[1]
currentHandsetSnumber = sys.argv[2]
command = sys.argv[3]
resultF = sys.argv[4]

filePath = sys.argv[5]



def calcMd5AndSave( handset,currentHandsetSnumber,resultF,filePath="./temp/result.txt",delay=5 ):
    setHandsetType(handset)
    setHandsetSno(currentHandsetSnumber)
    ret = False
    time.sleep(20)
    content = getAndSetMsgFromHandsetCliper("test",currentHandsetSnumber)
    dirMd5 = getMd5(content)
    if not os.path.exists(getHandsetFileSavePath(resultF)):
        os.makedirs(getHandsetFileSavePath(resultF))
    if not os.path.exists(getHandsetFileSavePath(resultF+dirMd5+"/")):
        #create it now and
        os.makedirs(getHandsetFileSavePath(resultF+dirMd5+"/"))
        with open(getHandsetFileSavePath(resultF  + "/curmd5.txt")) as f:
            print('wriete to file')
            f.write(dirMd5)
        with open(getHandsetFileSavePath(resultF+dirMd5+"/desc.txt")) as f:
            print('wriete to file')
            f.write(content)
    else:
        print('exist dir   '+dirMd5+'   now then  abort this task now--------')
        ret = True

    with open(getHandsetFileSavePath(resultF),'w')as f:
        if ret == True:
            f.write('True')
            return True  #TRUE 状态转移
        else:
            f.write('False')
            return False


if command =="calcMd5AndSave".strip():
    calcMd5AndSave(handset,currentHandsetSnumber,resultF,filePath)
